import 'package:flame/components/component.dart';
import 'package:flutter/material.dart';
import 'package:hello_flutter/demo/game/game_controller.dart';

class Player extends Component {
  final GameController controller; // 控制器
  Rect playRect; // 角色
  double maxHeath; // 最大生命值
  double currentHeath; // 当前生命值
  bool isDead = false; // 是否死亡

  Player(this.controller) {
    maxHeath = currentHeath = 300;
    final size = controller.tileSize * 1.5;
    playRect = Rect.fromLTWH(controller.screenSize.width / 2 - size / 2,
        controller.screenSize.height / 2 - size / 2, size, size);
  }

  @override
  void render(Canvas canvas) {
    final color = Paint()..color = Colors.blue;
    canvas.drawRect(playRect, color);
  }

  @override
  void update(double time) {
    if (!isDead && currentHeath <= 0) {
      isDead = true;

    }
  }
}
